package com.kifas.jobs;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.kifas.service.EntityServiceManager;

public class DailyStokUpdater implements Job {

	private EntityServiceManager serviceManager;

	private static final Logger log = Logger.getLogger(DailyStokUpdater.class);

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		serviceManager = (EntityServiceManager) context.getJobDetail().getJobDataMap().get("entityServiceManager");
		SimpleDateFormat formatter = new SimpleDateFormat("dd MMM YYYY");
		try {
			if(log.isDebugEnabled())
				log.debug("executing stok update.. for "+ formatter.format(new Date()));
			serviceManager.populateTodayStok();
		} catch (Exception e) {
			log.error("Could not execute job, error found", e);
		}
	}
}